--- tools/src/buildtools.orig	2018-01-14 19:03:28.356105100 +0800
+++ tools/src/buildtools	2018-01-14 19:07:24.392203592 +0800
@@ -172,6 +172,7 @@
     set -x
     # Fool autoconf and friends
     find . $FOOL_AC_FILES -print | xargs touch
+    export BZIP2CFLAGS="$BZIP2CFLAGS -fPIC"
     CFLAGS="$ALLCFLAGS $BZIP2CFLAGS"; export CFLAGS
     CPPFLAGS="$ALLCPPFLAGS $BZIP2CPPFLAGS"; export CPPFLAGS
     LDFLAGS="$ALLLDFLAGS $BZIP2LDFLAGS"; export LDFLAGS
@@ -305,7 +306,8 @@
     LD_LIBRARY_PATH=`pwd`
     DYLD_LIBRARY_PATH=`pwd`
     export LD_LIBRARY_PATH DYLD_LIBRARY_PATH
-    ./Configure -dOes -Ud_flock $PERLFLAGS -Ddosuid=undef -Dprefix=$INSTALLDIR -Dd_bincompat3=undef -A ldflags=-L${INSTALLDIR}/lib -A ccflags=-I${INSTALLDIR}/include -Ui_db -Ui_gdbm -Ui_ndbm -Ui_dbm -Uuse5005threads ; testordie "error configuring perl"
+    export PERLFLAGS="$PERLFLAGS -A libs=-lm -A libs=-ldl"
+    ./Configure -dOes -Ud_flock $PERLFLAGS -Ddosuid=undef -Dprefix=$INSTALLDIR -Dd_bincompat3=undef -A ldflags=-L${INSTALLDIR}/lib -A ccflags=-I${INSTALLDIR}/include -Ui_db -Ui_gdbm -Ui_ndbm -Ui_dbm -Uuse5005threads -Dcccdlflags="-fPIC -shared" -Dlddlflags="-shared -fPIC" -Duseshrplib=true ; testordie "error configuring perl"
     $MYMAKE; testordie "error building perl"
     ./perl installperl; testordie "error installing perl"
     setspecperllib
